package GA.chromosome;

import java.util.ArrayList;
import java.util.List;

import algorithm.AlgCtx;
import abstractGA.GAParameter;
import abstractGA.chrom.Chrom;

/**
 * 单目标GA带学习机制的染色体
 * 
 * @author nyc
 * 
 */
public class GAChrom extends Chrom {

	public GAChrom() {

	}

	public GAChrom(List<StringBuffer> codes) {
		this.codes = codes;
	}

	/**
	 * 构造函数
	 * 
	 * @param algCtx
	 *            ：算法运行上下文
	 * @param parameter
	 *            ：参数
	 */
	public GAChrom(AlgCtx algCtx, GAParameter parameter) {
		super(algCtx, parameter);
	}

	
	

	/**
	 * @return:复制并返回一条新的染色体
	 */
	public Chrom copy() {
		// 产生带学习机制的GA染色体
		GAChrom newChrom = new GAChrom();
		List<StringBuffer> newCodes = new ArrayList<StringBuffer>();
		int len = codes.size();
		for (int i = 0; i < len; i++) {
			String tempStr = codes.get(i).toString();
			newCodes.add(new StringBuffer(tempStr));
		}
		newChrom.codes = newCodes;
		
		ArrayList<StringBuffer> newObjVals = new ArrayList<>();
		for(StringBuffer objVal:objVals){
			newObjVals.add(objVal);
		}
		newChrom.objVals = newObjVals;

		newChrom.para = para;
		newChrom.random = random;
		newChrom.algOper = algOper;
		newChrom.listener = newChrom;
		return newChrom;
	}
	
}
